package com.acerola.mrpc.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @program: mrpc
 * @description: spring实例管理器
 * @author: Acerola
 * @create: 2022-12-14 16:17
 **/
@Component
public class SpringBeanManager implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringBeanManager.applicationContext = applicationContext;
    }

    /*
    根据类获取实例
     */
    public static  <T> T getBean(Class<T> clzz) {
        return applicationContext.getBean(clzz);
    }
}
